local skel = fk.CreateSkill {
  name = "emo__dingfan",
}

skel:addEffect("viewas", {
  anim_type = "offensive",
  prompt = function (self, player, selected_cards, selected)
    return "#emo__dingfan:::"..(2 + player:getMark("@emo__dingfan-phase"))
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = Util.FalseFunc,
  handly_pile = true,
  card_filter = function (self, player, to_select, selected)
    return #selected < (2 + player:getMark("@emo__dingfan-phase")) and table.contains(player:getHandlyIds(), to_select)
  end,
  view_as = function (self, player, cards)
    if #cards ~= (2 + player:getMark("@emo__dingfan-phase")) then return nil end
    local c = Fk:cloneCard(Fk:getCardById(cards[1]).color == Card.Black and "savage_assault" or "archery_attack")
    c.skillName = skel.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local targets = room:getOtherPlayers(player)
    local choices = {"savage_assault", "archery_attack"}
    local result = room:askToJointChoice(player, {
      players = targets,
      choices = choices,
      skill_name = skel.name,
      prompt = "#emo__dingfan-choice",
      send_log = true,
    })
    local list = {}
    for p, choice in pairs(result) do
      if choice == use.card.name then
        table.insert(list, p)
      end
    end
    use.nullifiedTargets = list
    if #list == #targets then
      room:addPlayerMark(player, "@emo__dingfan-phase", 1)
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__dingfan"] = "定藩",
  [":emo__dingfan"] = "出牌阶段，你可以选择颜色相同的两张手牌，令所有其他角色猜测颜色，然后你将这些牌按颜色转化使用（黑色/红色当【南蛮入侵】/【万箭齐发】），此牌对猜对的角色无效。若所有其他角色均猜对，本阶段内发动此技能所需牌数+1。",

  ["#emo__dingfan-choice"] = "定藩：选择对你无效的牌名",
  ["@emo__dingfan-phase"] = "定藩",
  ["#emo__dingfan"] = "定藩：选择 %arg 张同颜色手牌，黑色当【南蛮入侵】/红色当【万箭齐发】使用",
}

return skel
